#pragma once

#include <vector>
#include <string>

#include "common.h"

#include "MyExcel.h"

class ExcelDataTable
{
public:
	ExcelDataTable(void);
	~ExcelDataTable(void);

	bool parseData( const std::string& file, const std::string& sheet, const stOutput& table );

	std::string getData( const int field, const int index ) const;
	void setData( const int field, const int index, const std::string& value );
	void addData( const int field, const std::string& value );
	int getSize() const;
	void setFieldCount( const int count );
	int getFieldCount() const;

protected:
	bool openExcel( CMyExcel& excel, const std::string& file, const std::string& sheet ) const;
	int getExcelData( 
		CMyExcel& excel, 
		const stField& field, 
		const int rows,
		std::vector< std::string >& data ) const;
	int getFieldExcelIndex( CMyExcel& excel, const std::string& field ) const;
	

private:
	std::vector< std::vector< std::string > >	m_data;
};


inline std::string ExcelDataTable::getData( const int field, const int index ) const
{
	if( ( int )m_data.size() <= field )
		return "";
	if( ( int )m_data[field].size() <= index )
		return "";
	return m_data[field][index];
}

inline void ExcelDataTable::setData( const int field, const int index, const std::string& value )
{
	if( ( int )m_data.size() <= field )
		return;
	if( ( int )m_data[field].size() <= index )
		return;	
	m_data[field][index] = value;
}

inline void ExcelDataTable::addData( const int field, const std::string& value )
{
	if( ( int )m_data.size() <= field )
		return;	
	m_data[field].push_back( value );
}

inline int ExcelDataTable::getSize() const
{
	if( m_data.empty() )
		return 0;
	return ( int )m_data[0].size();
} 

inline void ExcelDataTable::setFieldCount( const int count )
{
	m_data.resize( count );
}

inline int ExcelDataTable::getFieldCount() const
{
	return ( int )m_data.size();
}